package net.wanho.systemSettings.dao.impl;

import net.wanho.commons.exception.DaoException;
import net.wanho.commons.exception.DataAccessException;
import net.wanho.commons.factory.BeanFactory;
import net.wanho.commons.util.JDBCTemplate;
import net.wanho.systemSettings.dao.EmployeeDao;
import net.wanho.systemSettings.po.Position;
import net.wanho.systemSettings.vo.EmployeeVo;

public class EmployeeDaoImpl implements EmployeeDao {
    private JDBCTemplate jdbcTemplate = BeanFactory.getBean(JDBCTemplate.class) ;
    @Override
    public EmployeeVo selectByIdEmployeeVo(Integer employeeId) throws DaoException {
        final String SELECT_BY_ID_EMPLOYEE_AND_LOG_IN_SQL = "SELECT\n" +
                "  e.EMPLOYEE_ID           EMPLOYEEID,\n" +
                "  e.EMPLOYEE_NAME         EMPLOYEENAME,\n" +
                "  e.DEPARTMENT_ID         DEPARTMENTID,\n" +
                "  e.POSITON_ID            POSITONID,\n" +
                "  e.PHONE                 PHONE,\n" +
                "  e.EMAIL                 EMAIL,\n" +
                "  e.STATUS                STATUS,\n" +
                "  e.PARENT_EMPLOYEE_ID    PARENTEMPLOYEEID,\n" +
                "  e.CREATE_TIME           CREATETIME,\n" +
                "  e.UPDATE_TIME           UPDATETIME,\n" +
                "  l.EMM_PASSWORD          EMMPASSWORD\n" +
                "FROM employee e\n" +
                "  JOIN log_in l\n" +
                "    ON e.EMPLOYEE_ID = l.EMPLOYEE_ID\n" +
                "WHERE l.EMPLOYEE_ID = ?" ;
        try {
            return jdbcTemplate.queryForObject(SELECT_BY_ID_EMPLOYEE_AND_LOG_IN_SQL, EmployeeVo.class,employeeId);
        } catch (DataAccessException e) {
            e.printStackTrace();
            throw new DaoException(e.getMessage()) ;
        }
    }
}
